package win;

import java.io.*;

public class Win {
    private static String homePath = null;

    static {
        InputStreamReader ir = null;
        BufferedReader br = null;
        try {
            File batFile = new File("src\\win\\getHomeDir.bat");
            Process p = Runtime.getRuntime().exec(batFile.getAbsolutePath());
            ir = new InputStreamReader(p.getInputStream());
            br = new BufferedReader(ir);
            homePath = br.readLine();
        } catch (IOException e) {
        } finally {
            try {
                if (null != ir) ir.close();
                if (null != br) br.close();
            } catch (Exception e) {
            }
        }
    }

    public static String getHomePath() {
        return homePath;
    }

    public static int changeWallpaper(String imgPath) {
        Process p = null;
        try {
            File batFile = new File("src\\win\\changeWallpaper.exe");
            p = Runtime.getRuntime().exec(batFile.getAbsolutePath() + " " + imgPath);
            p.waitFor();
        } catch (IOException e) {
        } catch (InterruptedException e) {
        }
        if (p != null) return p.exitValue();
        else return -1;
    }
}
